
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
import org.fusesource.jansi.AnsiConsole;

public class ConsultaHosp {
	
	public static void cohosp() {
		AnsiConsole.out.print("\u001b[2J");
		Scanner dados = new Scanner(System.in);
		System.out.println("___________________________________Hemouna______________________________________");
		System.out.println("_____________________________Consulta - Hospital________________________________");
		System.out.println("\n\n\n");
		try{
			Class.forName("org.hsqldb.jdbcDriver" ); 	    
			Connection con = DriverManager.getConnection("jdbc:hsqldb:file:Banco/BD", "sa", "");
			Statement stm = con.createStatement();			
			System.out.println("Os hospitais cadastrados sao\n");
			ResultSet rs = stm.executeQuery("SELECT * FROM hospital");
			System.out.printf("+---------------+--------------------------------------------------------------+");
			System.out.printf("|     CNPJ      |                           Nome                               |");
			System.out.printf("+---------------+--------------------------------------------------------------+");
			while(rs.next()){
				String nome = rs.getString("nome");
				String cnpj = rs.getString("cnpj");
				System.out.printf("|"+Espaco.add(cnpj, 14)+"|"+Espaco.add(nome, 61)+"|");  
			}
			System.out.printf("+---------------+--------------------------------------------------------------+\n\n");
			stm.execute("SHUTDOWN");
			System.out.println("Pressione uma tecla para voltar ao menu");
			System.in.read();
		}catch(ClassNotFoundException e){
		    System.out.println("Erro ao carregar o driver JDBC. ");
		}catch(Exception e){
		    System.out.println("Erro de SQL: "+e);
		    e.printStackTrace();
		}
		MenuConsulta.meconsulta();
	}

}
